﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using BobDotNet.Classes.Base;

namespace BobDotNet.Classes.Dao
{
    public class DaoBase
    {
        public static object Charge(Int32 id, string name)
        {
            NHibernateSessionManager.Instance.GetSession();
            object retour = NHibernateSessionManager.Instance.GetSession().Get(name, id);
            NHibernateSessionManager.Instance.CloseSession();
            return retour;
        }

        public static void MettreAJour(object o)
        {
            try
            {
                NHibernateSessionManager.Instance.GetSession();
                NHibernateSessionManager.Instance.BeginTransaction();
                NHibernateSessionManager.Instance.GetSession().Update(o);
                NHibernateSessionManager.Instance.CommitTransaction();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static void Creer(object o)
        {
            try
            {
                NHibernateSessionManager.Instance.GetSession();
                NHibernateSessionManager.Instance.BeginTransaction();
                NHibernateSessionManager.Instance.GetSession().Save(o);
                NHibernateSessionManager.Instance.CommitTransaction();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static void Supprimer(object o)
        {
            try
            {
                NHibernateSessionManager.Instance.GetSession();
                NHibernateSessionManager.Instance.BeginTransaction();
                NHibernateSessionManager.Instance.GetSession().Delete(o);
                NHibernateSessionManager.Instance.CommitTransaction();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}